package com.thinking.live.hanlder;

import cn.hutool.core.util.ObjectUtil;

import com.thinking.live.entity.pojo.resp.RechargeMoneyResp;
import com.thinking.live.event.OrderPayResultDTOEvent;
import com.thinking.live.service.LiveChargeService;
import com.thinking.live.vo.dto.OrderPayResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/***
 @author tangsixiang@hotmail.com
 描述：
 @date 2024年01月10日 9:39
 */

@Slf4j
@Component
public class LivingChargePayListener implements ApplicationListener<OrderPayResultDTOEvent> {

    @Autowired
    @Lazy
    LiveChargeService liveChargeService;
    @Override
    @Async
    public void onApplicationEvent(OrderPayResultDTOEvent event) {
        OrderPayResultDTO orderPayResultDTO = event.getOrderPayResultDTO();
        log.info("pay-status-sucess-data:{}",orderPayResultDTO);
        if(ObjectUtil.isNotEmpty(orderPayResultDTO)){
            RechargeMoneyResp rechargeMoneyResp = liveChargeService.sendChargeDataToThird(orderPayResultDTO);
            log.info("pay-status-sucess-data-resp:{}",rechargeMoneyResp);
        }
    }
}
